import { BasicDrawer, useDrawerInner } from "@/components/Drawer";
import { BasicForm, FormSchema, useForm } from "@/components/Form";
import { message } from "antd";
import { useTranslation } from "react-i18next";
import "./index.less";
import { drugInfoApi } from "@/api/erp/drug/drugCatalogue";
const index = (props: { register: Fn }) => {
	const { t } = useTranslation();
	const en_vi = "MedicalExamination.prescribe";
	const formSchema: FormSchema[] = [
		{
			label: t(`${en_vi}.drugCode`),
			field: "drugId",
			component: "Input",
			componentProps: {
				disabled: true
			}
		},
		{
			label: t(`${en_vi}.drugName`),
			field: "drugName",
			component: "Input",
			componentProps: {
				disabled: true
			}
		},
		{
			label: t(`${en_vi}.storageConditions`),
			field: "storageCond",
			component: "Input",
			componentProps: {
				disabled: true
			}
		},
		{
			label: t(`${en_vi}.purchasePrice`),
			field: "purPrice",
			component: "Input",
			componentProps: {
				disabled: true
			}
		},
		{
			label: t(`${en_vi}.sellingPrice`),
			field: "salePrice",
			component: "InputNumber"
		}
	];

	const [registerDrawer, { closeDrawer }] = useDrawerInner(props.register, async data => {
		await resetFields();
		setFieldsValue(data.record);
	});

	const [register, { validateFields, setFieldsValue, resetFields }] = useForm({
		schemas: formSchema,
		labelWidth: 100,
		baseColProps: {
			span: 24
		},
		initialValues: {
			status: "0"
		}
	});
	const handleSubmit = async () => {
		const formValue = await validateFields();
		const res = drugInfoApi.rugPriceAdjustCreate({
			drugId: formValue.drugId,
			salePrice: formValue.salePrice
		});
		if (!res) return message.error(t("kevin_ui.addFailed"));
		message.success(t("kevin_ui.addedSuccessfully"));
		closeDrawer();
	};
	return (
		<BasicDrawer showFooter={true} {...props} register={registerDrawer} ok={handleSubmit}>
			<div className="warehouses">
				<BasicForm register={register}></BasicForm>
			</div>
		</BasicDrawer>
	);
};
export default index;
